package com.cpr.core.rabbitmq.springctl.anno;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;

/**
 * @author Chen Panrui
 * created at 2022/3/16 0:27
 */
@Component
public class MyMessageListener {

    /**
     * com.rabbitmq.client.Channel to get access to the Channel
     * org.springframework.amqp.core.Message or one if subclass to get access to the raw AMQP message
     * org.springframework.messaging.Message to use the messaging abstraction counterpart
     * @Payload-annotated method arguments including the support of validation 注解方法参数，该参数的值就是message消息体
     * @Header-annotated method arguments to extract a specific header value, including standard AMQP headers defined by AmqpHeaders
     * @Headers-annotated argument that must also be assignable to java.util.Map for getting access to all headers.
     * MessageHeaders arguments for getting access to all headers.
     * MessageHeaderAccessor or AmqpMessageHeaderAccessor for convenient access to all method arguments.
     */
    //@RabbitListener(queues = "queue.anno")
    public void onMessage(Message message) throws UnsupportedEncodingException {
        System.out.println(new String(message.getBody(), message.getMessageProperties().getContentEncoding()));
    }

    @RabbitListener(queues = "queue.anno")
    public void onMessage(@Payload String messageStr){
        System.out.println("listener消息:" + messageStr);
    }



}
